package com.weichen.xd;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * Created by Dune on 2017/9/4.
 */

public class LAdapter extends BaseAdapter {

    private String[] a = {
            "a",
            "b",
            "c",
            "d",
            "e",
            "f",
            "g",
            "a1",
            "a2",
            "a3j",
            "a4",
            "a5",
    };


    @Override
    public int getCount() {
        return a.length;
    }

    @Override
    public Object getItem(int position) {
        return a[position];
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder;

        Log.e("adapter view ", String.valueOf(convertView == null));

        if (view == null) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            view = inflater.inflate(R.layout.item_moment, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);

        } else {

            holder = (ViewHolder) view.getTag();
        }


        holder.textView.setText(a[position]);


        return view;
    }


    private static class ViewHolder {

        TextView textView;

        public ViewHolder(View view) {
            textView = (TextView) view.findViewById(R.id.tv_nickname);
        }
    }

}
